import cv2 as cv
import numpy as np


def fill_mix_range(img):
    h,w = img.shape[:2]
    mask = np.zeros([h+2, w+2],np.uint8)
    cv.floodFill(img,mask,(10,10),(0,0,255),(90,90,90),(20,20,20),cv.FLOODFILL_FIXED_RANGE)
    cv.imshow('floodfill_fixed',img)


def fill_binary():
    src = np.zeros([400,400,3],np.uint8)
    src[100:300,100:300,:] = 255
    cv.imshow('src',src)
    mask = np.ones([402,402,1],np.uint8)
    mask[101:301,101:301] = 0
    cv.floodFill(src,mask,(200,200),(0,0,255),cv.FLOODFILL_MASK_ONLY)
    cv.imshow('fill_binary',src)


src = cv.imread('lena.jpg', 1)
cv.namedWindow('demo',cv.WINDOW_AUTOSIZE)
cv.imshow('demo', src)

"""
face = src[100:240, 100:220]
cv.imshow('face',face)
gray_face = cv.cvtColor(face, cv.COLOR_BGR2GRAY)
cv.imshow('gray_face',gray_face)
back_face = cv.cvtColor(gray_face, cv.COLOR_GRAY2BGR)
cv.imshow('back_face',back_face)
src[100:240, 100:220] = back_face
cv.imshow('gray_face lena',src)
"""
# fill_mix_range(src)
fill_binary()
cv.waitKey(0)
cv.destroyWindow('demo')